home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Report Writers / Crystal Repot 9.0 Full CD version / Setup.exe / Tools / Developers / PEDELF32.ZIP / pedelf32 / PRNTOPT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-09-30  |  2.8 KB  |  96 lines

  1. unit Prntopt;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, CRDelphi;
  8.                
  9.  
  10.  
  11. type
  12.   TFrmPrintOptions = class(TForm)
  13.     BtnOK: TBitBtn;
  14.     LblStart: TLabel;
  15.     LblStop: TLabel;
  16.     LblCopies: TLabel;
  17.     LblCollation: TLabel;
  18.     EdtStart: TEdit;
  19.     EdtStop: TEdit;
  20.     EdtCopies: TEdit;
  21.     EdtCollation: TEdit;
  22.     BtnSetPrintOptions: TBitBtn;
  23.     procedure FormShow(Sender: TObject);
  24.     procedure BtnSetPrintOptionsClick(Sender: TObject);
  25.     function GetError(Const JobIn : Integer) : String;
  26.  
  27.   private
  28.     { Private declarations }
  29.   public
  30.     { Public declarations }
  31.   end;
  32.  
  33. var
  34.   PrintOptions : PEPrintOptions;
  35.   FrmPrintOptions: TFrmPrintOptions;
  36.  
  37. implementation
  38.    uses main;
  39. {$R *.DFM}
  40.  
  41. function TFrmPrintOptions.GetError(Const JobIn : Integer) : String;
  42. {This is my print engine error message capture function. It accepts
  43.  the job number as it parameter and then gets the error code and
  44.  message text and then passes this back out as a formatted string}
  45. var
  46.   Code : SmallInt;
  47.   StrHandle : hWnd;
  48.   Buffer : PChar;
  49.   Length : SmallInt;
  50.   Ret : Bool;
  51.  
  52. begin
  53.    Code := PEGetErrorCode(JobIn); {Get the Error code from the Crpe}
  54.    Ret := PEGetErrorText(JobIn, StrHandle, Length);  {Get the error message handle}
  55.  
  56.    Buffer := StrAlloc(Length);
  57.    {get the text from the text handle}
  58.    Ret := PEGetHandleString(StrHandle, Buffer, Length);
  59.  
  60.    GetError := IntToStr(Code) + ' - ' + StrPas(Buffer); {output the string}
  61.    StrDispose(Buffer);
  62. end;
  63.  
  64. procedure TFrmPrintOptions.FormShow(Sender: TObject);
  65.  
  66. begin
  67.    PrintOptions.StructSize := Sizeof(PEPrintOptions);  {Initialize the structure size}
  68.    {Get the default print options from the Report}
  69.    if PeGetPrintOptions(JobNumber, PrintOptions) then
  70.       begin
  71.          {fill the edit boxes with the results of the PE call}
  72.          EdtStart.Text := IntToStr(PrintOptions.StartPageN);
  73.          EdtStop.Text := IntToStr(PrintOptions.StopPageN);
  74.          EdtCopies.Text := IntToStr(PrintOptions.NReportCopies);
  75.          EdtCollation.Text := IntToStr(PrintOptions.Collation);
  76.       end
  77.    else  {call failed}
  78.       ShowMessage(GetError(JobNumber)); {show any error messages}
  79.  
  80. end;
  81.  
  82. procedure TFrmPrintOptions.BtnSetPrintOptionsClick(Sender: TObject);
  83.  
  84. begin
  85.    {Populate the print options Structure}
  86.    PrintOptions.StartPageN := StrToInt(EdtStart.Text);
  87.    PrintOptions.StopPageN := StrToInt(EdtStop.Text);
  88.    PrintOptions.NReportCopies := StrToInt(EdtCopies.Text);
  89.    PrintOptions.Collation := StrToInt(EdtCollation.Text);
  90.  
  91.    {set the new options for printing}
  92.    if PeSetPrintOptions(JobNumber, PrintOptions) = False then
  93.       ShowMessage(GetError(JobNumber)); {show any error messages}
  94. end;
  95. end.
  96.